<?php
/**
 * @Copyright Copyright (C) 2010-2012
 * @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
 + Created by:          Webit Solution
 * Company:		Webit Solution
 + Contact:		www.webits.asia, developer@webits.asia
 * Created on:	Mar 21, 2012
 ^
 + Project: 		WRecruit
 * File Name:	views/employer/tmpl/formjob.php
 ^ 
 * Description: template for form job
 ^ 
 * History:		NONE
 ^ 
 */
 

defined('_JEXEC') or die('Restricted access');

 global $mainframe;
$document =& JFactory::getDocument();

//$document->addScript( 'components/com_wrecruit/js/jquery-1.7.2.min.js' );
//$document->addScript( 'components/com_wrecruit/js/jquery-ui.min.js' );
//$document->addScript( 'components/com_wrecruit/js/jquery.uniform.js' );
//$document->addScript( 'components/com_wrecruit/js/scripts.js' );
$document->addScript( 'components/com_wrecruit/js/emppopup.js' );
$document->addStyleSheet('components/com_wrecruit/css/emppopup.css');
$document->addStyleSheet('components/com_wrecruit/css/other_employers.css');
$model = $this->getModel('wrecruit', 'WRecruitModel');
 
//add multi select 
$document->addStyleSheet('components/com_wrecruit/css/chosen/chosen.css');
//end
 
jimport('joomla.html.pane');

$editor = & JFactory :: getEditor();
JHTML :: _('behavior.calendar');

    $document = &JFactory::getDocument();
    $document->addStyleSheet('components/com_wrecruit/css/'.$this->config['theme']);
	$version = new JVersion;
	$joomla = $version->getShortVersion();
	$jversion = substr($joomla,0,3);

	$dateformat = $this->config['date_format'];
	$firstdash = strpos($dateformat,'-',0);
	$firstvalue = substr($dateformat, 0,$firstdash);
	$firstdash = $firstdash + 1;
	$seconddash = strpos($dateformat,'-',$firstdash);
	$secondvalue = substr($dateformat, $firstdash,$seconddash-$firstdash);
	$seconddash = $seconddash + 1;
	$thirdvalue = substr($dateformat, $seconddash,strlen($dateformat)-$seconddash);
	$js_dateformat = '%'.$firstvalue.'-%'.$secondvalue.'-%'.$thirdvalue;
  
?>
<?php if ($this->config['offline'] == '1'){ ?>
<table cellpadding="0" cellspacing="0" border="0" width="100%" >
	<tr><td valign="top" class="<?php echo $this->theme['title']; ?>" >	<?php echo $this->config['title']; ?></td></tr>
	<tr><td height="25"></td></tr>
	<tr><td class="wrecruitmsg">
		<?php echo $this->config['offline_text']; ?>
	</td></tr>
</table>	
<?php }else{ ?>
<script language="javascript">
	function hideShowRange(hideSrc, showSrc, showName, showVal){
		document.getElementById(hideSrc).style.visibility = "hidden";
		document.getElementById(showSrc).style.visibility = "visible";
		document.getElementById(showName).value = showVal;
	
	}
 
	function myValidate(f) {
		var returnvalue = true;
		
	/*	if (f.id.value == ''){
			if (CheckDate()== false) returnvalue = false; 
		}*/		
		if (document.formvalidator.isValid(f)) {
                f.check.value='<?php echo JUtility::getToken(); ?>';//send token
        } else {
                alert('<?php echo JText::_( 'JS_SOME_VALUES_ARE_NOT_ACCEPTABLE_PLEASE_RETRY');?>');
				returnvalue = false;
        }
		if (returnvalue == true)
			return true;
		else{	
			return false;
		}	
}

function CheckDate() {
//alert('date');
	f = document.adminForm;
	var returnvalue = true;
	var today=new Date()
	if ((today.getMonth()+1) < 10)
		var tomonth = "0"+(today.getMonth()+1);
	else
		var tomonth = (today.getMonth()+1);
	
	if ((today.getDate()) < 10)
		var day = "0"+(today.getDate());
	else
		var day = (today.getDate());

		var todate = (today.getYear()+1900)+"-"+tomonth+"-"+day;
	
//alert(todate); 
		if(f.startpublishing.value != ""){
			if (todate > f.startpublishing.value ){
				alert('Please enter a valid start publishing date');
				f.startpublishing.value="";
				returnvalue = false;
			}
		}		
		if(f.startpublishing.value >= f.deadline.value){
			alert("Please enter a valid dateline");
			f.deadline.value="";
			returnvalue = false;
		}
		return returnvalue;
	
}

function isAdded(id) {
	if(document.getElementById(id).checked==true){
		document.getElementById(id).value = 1;
	}
	else{
		document.getElementById(id).value = 0;
	}
	
}
</script>
<?php
if ($this->userrole->rolefor == 1) { // employer
//if ($this->canaddnewjob == 1) { // add new job, in edit case always 1
?>
<div class="box-list-job">
	<div class="job-seeker-panel">
	<?php include 'left_panel.php';?>
	</div>
	<div class="job-seeker-right">
		<div class="head-title">
			<h2>Post a new job vacancy</h2>
		</div>
			<form action="index.php" method="post" name="adminForm" id="adminForm" class="form-validate"  onSubmit="return myValidate(this);">
    			<div class="post-job post-top">
						<h4>Job description</h4>
	    			<table cellpadding="5" cellspacing="0" border="0" width="100%" class="adminform" style="position: relative;">
		
						<tr>
							<td width="17%" align="right">
								<label id="titlemsg" for="title"><?php echo JText::_('JS_JOB_TITLE').':'; ?></label>
								&nbsp;<font color="red">*</font>
							</td>
							<td>
								<input class="inputbox required" type="text" name="title" id="job-title" size="40" maxlength="255" value="<?php if(isset($this->job)) echo $this->job->title; ?>" />
								<input type="hidden" name="companyid" value="<?php echo $this->wr_company->id; ?>"></input>
							</td>
						</tr>
						<tr>
							<td valign="top" align="right"><label><?php echo 'Industry:'; ?>&nbsp;</label><font color="red">*</font></td>
							<td>
								<?php echo $this->lists['jobcategory']; ?>
							</td>
						</tr>
					
						<tr>
							<td valign="top" align="right">
							<label id="careerlevelmsg" for="careerlevel"><?php echo JText::_('JS_CAREER_LEVEL').':'; ?></label>
							</td>
							<td><?php echo $this->lists['careerlevel']; ?></td>
						</tr>
						
							 
						<tr>
							<td valign="top" align="right"><label><?php echo JText::_('JS_JOBTYPE').':'; ?></label></td>
				        	<td ><?php echo $this->lists['jobtype']; ?></td>
						</tr>
						
						<tr>
							<td valign="top" align="right"><label><?php echo 'Working shift:' ?></label>
								<input type="hidden" name="jobtype" value="3">
							</td>
							<td><?php echo $this->lists['shift']; ?> 
								<label id="" for="deadline">
									<?php echo 'Deadline:' ?>
								</label>
									<?php if($this->packagedetail[2] == 1){
									if(isset($this->job)){ 
										if($jversion == '1.5') { ?> <input class="inputbox required" type="text" name="deadline" id="job_deadline" readonly class="Shadow Bold" size="10" value="<?php if(isset($this->job)) echo  date($this->config['date_format'],strtotime($this->job->deadline)); ?>" />
										<?php } 
										else { echo JHTML::_('calendar', $this->job->deadline,'deadline', 'job_deadline',$js_dateformat,array('class'=>'inputbox required', 'size'=>'10',  'maxlength'=>'19','readonly'=>'readonly')); ?>
												<?php } ?>
										  <?php }else{
												if($this->packagedetail[4] == 1) $enforcetype = JText::_('JS_DAYS');
												elseif($this->packagedetail[4] == 2) $enforcetype = JText::_('JS_WEEKS');
												elseif($this->packagedetail[4] == 3) $enforcetype = JText::_('JS_MONTHS');
												echo $this->packagedetail[3].' '.$enforcetype;
											    }
		                                }else {
											if($jversion == '1.5'){ ?><input class="inputbox required" type="text" name="deadline" id="job_deadline" readonly class="Shadow Bold" size="10" value="<?php if(isset($this->job)) echo  date($this->config['date_format'],strtotime($this->job->deadline)); ?>" />
												<input type="reset" class="button" value="..." onclick="return showCalendar('job_deadline','<?php echo $js_dateformat; ?>');"  />
		
											<?php 
											}else echo JHTML::_('calendar', $this->job->deadline,'deadline', 'job_deadline',$js_dateformat,array('class'=>'inputbox required', 'size'=>'10',  'maxlength'=>'19')); ?>
		
								<?php   } ?>
							</td>
						</tr>
						<tr>
							<td valign="top" align="right"><label><?php echo 'Reference number:' ?></label></td>
							<td>Job reference number (auto generated and just displayed here)…</td>
						</tr>
						<?php if ( $this->config['job_editor'] == 1 ) { ?>
								<tr><td height="10" colspan="54"></td></tr>
								<tr>
									<td colspan="54" valign="top"><label id="descriptionmsg" for="description"><strong>Job description:</strong></label>&nbsp;<font color="red">*</font></td>
								</tr>
								<tr>
									<td colspan="54" align="left">
									<?php
										$editor =& JFactory::getEditor();
										if(isset($this->job))
											echo $editor->display('description', $this->job->description, '500', '200', '60', '20', false);
										else
											echo $editor->display('description', '', '500', '200', '60', '20', false);
	
									?>	
						
									</td>
								</tr>
						<?php }else{ ?>
								<tr>
									<td valign="top" align="right">
										<label id="descriptionmsg" for="description"><strong><?php echo JText::_('JS_DESCRIPTION').':'; ?></strong></label>&nbsp;
										<font color="red">*</font>
									</td>
									<td >
										<textarea class="inputbox required" name="description" id="description" cols="60" rows="5"><?php if(isset($this->job)) echo $this->job->description; ?></textarea>
									</td>
								</tr>
						<?php } ?>
						<tr>
							<td colspan="54">Do not include contact information like phone
								number or email address.</td>
						</tr>
						<tr>
							<td colspan="54">
								<input onclick="isAdded(this.id)" type="checkbox" name="company_desc_included" id="compdesc" value="0">
									&nbsp;&nbsp;Include	company description in job description.&nbsp;&nbsp;&nbsp; 
								<input onclick="isAdded(this.id)" type="checkbox" name="isApplicable" id="applicable" value="0">&nbsp;&nbsp;Applicable?
							</td>
						</tr>
					</table>
				</div>
				<div class="post-job">
					<h4>Job requirement</h4>
					<table>
						<tr>
							<td valign="top" align="right"><label id="gendermsg" for="gender"><?php echo 'Required gender:'; ?>
							<?php if($field->required == 1) echo '&nbsp;<font color="red">*</font>'; ?>
							</label></td>
							<td><?php echo $this->lists['gender']; ?></td>
						</tr>
	
						<tr>
							<td valign="top" align="right"><label id="agefrommsg"
								for="agefrom"><?php echo 'Required age:'; ?> </label> 
								<?php if($field->required == 1) echo '&nbsp;<font color="red">*</font>'; ?>
							</td>
							<td><?php echo $this->lists['agefrom']; ?>&nbsp;&nbsp;&nbsp; <?php echo $this->lists['ageto']; ?>
							</td>
						</tr>
						<tr>
							<td valign="top" align="right"><label><?php echo 'Education level:'; ?></label>
							</td>
							<td height="31" valign="top"><?php echo $this->lists['education']; ?>
							</td>
						</tr>
						<tr>
							<td valign="top" align="right"><label id="requiredtravelmsg"
								for="requiredtravel"><?php echo JText::_('JS_REQUIRED_TRAVEL').':'; ?>
							</label>
							</td>
							<td><?php echo $this->lists['requiredtravel']; ?></td>
						</tr>
						<tr>
							<td valign="top" align="right"><label id="experiencesmsg"
								for="experience"><?php echo 'Years of experience:'; ?></label>
							</td>
							<td height="31" valign="top">Min&nbsp;&nbsp;<?php echo $this->lists['minimumexperiencerange']; ?>
								&nbsp;&nbsp;&nbsp; Max&nbsp;&nbsp;<?php echo $this->lists['maximumexperiencerange']; ?>
							</td>
	
						</tr>
						
						<tr>
					        <td align="right"><label id="countrymsg" for="country"><?php echo JText::_('JS_COUNTRY').':'; ?></label></td>
					        <td  id="job_country">
							      <?php echo $this->lists['country']; ?>
					        </td>
					     </tr>
						
						<tr>
					        <td align="right"><label id="citymsg" for="city"><?php echo JText::_('JS_CITY').':'; ?></label></td>
					        <td  id="job_city">
							<?php 
								if((isset($this->lists['city'])) && ($this->lists['city']!='')){
									echo $this->lists['city']; 
								} else{ ?>
									<input class="inputbox" type="text" name="city" size="40" maxlength="100" value="<?php if(isset($this->job)) echo $this->job->city; ?>" />
								<?php } ?>
					        </td>
					      </tr>
						
						<tr>
							<td valign="top" align="right">Other experience:</td>
							<td height="31" valign="top"><input class="inputbox" type="text"
								name="experiencetext" id="experiencetext" size="30"
								maxlength="150"
								value="<?php if(isset($this->job)) echo $this->job->experiencetext; ?>" />
							</td>
						</tr>
						<?php if ( $this->config['job_editor'] == 1 ) { ?>	
								<tr>
									<td colspan="54" align="left">
									<?php
										$editor =& JFactory::getEditor();
										if(isset($this->job))
											echo $editor->display('qualifications', $this->job->qualifications, '500', '200', '60', '20', false);
										else
											echo $editor->display('qualifications', '', '500', '200', '60', '20', false);
	
									?>	
									</td>
								</tr>
						<?php }else{ ?>
								<tr>
									<td valign="top" align="right"><label id="descriptionmsg" for="description"><?php echo JText::_('JS_DESCRIPTION'); ?></label>&nbsp;<font color="red">*</font></td>
									<td ><textarea class="inputbox required" name="description" id="description" cols="60" rows="5"><?php if(isset($this->job)) echo $this->job->description; ?></textarea></td>
								</tr>
						<?php } ?>
						<tr>
							<td colspan="2">Do not include contact information like phone
								number or email address.</td>
						</tr>
					</table>
				</div>
			    <div class="post-job">
			    	<h4>Job allowance and benefit</h4>
					<table>	
						<tr>
							<td valign="top" align="right"><?php echo JText::_('JS_SALARYRANGE').':'; ?>
							</td>
							<td><?php echo $this->lists['salaryrangefrom']; ?>&nbsp;&nbsp;&nbsp;
							<?php echo $this->lists['salaryrangeto']; ?>&nbsp;&nbsp;&nbsp; <?php echo $this->lists['salaryrangetypes']; ?>&nbsp;&nbsp;&nbsp;
							</td>
						</tr>
						<tr>
							<td colspan="2"><textarea name="morebenefit"
									id="morebenefit" cols="60" style="text-align: left;width:490px; height:90px;" rows="5">
									<?php if(isset($this->job)) echo $this->job->morebenefit;else echo 'more allwance and benefit...';?>
								</textarea>
							</td>
						</tr>
						<tr>
							<td colspan="2">Do not include contact information like phone
								number or email address.</td>
						</tr>
					</table>
				</div>
				<div class="post-job">
					<h4>Invite your candidates</h4>
					<table>	
						<tr>
							<td colspan="2">If you have found and keep your potential
								candidates, you can invite them to apply to this vacancy. <br />We
								will notify them after this vacancy is published.</td>
						</tr>
	
						<tr>
							<td valign="top">Candidate name:</td>
							<td>
								<div class="side-by-side clearfix">
							      <div>
							        <select name="candidate_list[]" data-placeholder="Candidate names..." style="width:350px;" multiple class="chzn-select" tabindex="8">
							          <option value=""></option>
							          <?php if (!empty($this->candidatepools)) {?>
									  <?php foreach ($this->candidatepools as $candidate){?>
							          	<option value="<?php echo $candidate->email;?>"><?php echo $candidate->name;?></option>
							          <?php }?>
                                      <?php }?>
							        </select>							      
							      </div>    
							  </div>
							</td>
						</tr>
						<tr>
							<td height="10" colspan="2"></td>
						</tr>
                       </table>
                       </div>
                       <div class="post-jobs" style="width: 530px; float: left; margin-bottom: 20px;">
                       <table width="100%">
						<tr>
							<td>
								<span style="text-decoration: underline; cursor: pointer; font-weight: bold; padding: 5px 0px 0px;" class="wepopup" id="jobpreview">Preview</span>
							</td>
							<td align="center" style="float: right; padding: 0px;">
                            		
                             <div class="wrapp-btn">
                            	<span class="btn-left"><span class="btn-right"><input type="submit" name="submit_app" value="<?php echo 'Save&New'; ?>" class="btn" id="job-save-new" /> &nbsp;</span></span>
                            </div>
                            <div class="wrapp-btn">
                            	<span class="btn-left"><span class="btn-right"><input type="submit" name="submit_app" value="<?php if(isset($this->job)) echo 'Change'; else echo 'Save'; ?>"  class="btn" id="job-save" />&nbsp;</span></span>
                                <span class="star1">&nbsp;</span>
                            </div>
							</td>
						</tr>
					</table>
				</div>
				<?php
				if(isset($this->job)) {
					if (($this->job->created=='0000-00-00 00:00:00') || ($this->job->created==''))
					$curdate = date('Y-m-d H:i:s');
					else
					$curdate = $this->job->created;
				}else
				$curdate = date('Y-m-d H:i:s');
					
				?>
			<input type="hidden" name="startpublishing" id="startpublishing" value="<?php echo $curdate; ?>" >
			<input type="hidden" name="created" value="<?php echo $curdate; ?>" />
			<input type="hidden" name="uid" value="<?php echo $this->uid; ?>" />
			<input type="hidden" name="option" value="<?php echo $this->option; ?>" />
			<input type="hidden" name="task" value="savetojob" />
			<input type="hidden" name="check" value="" />
			<input type="hidden" name="packageid" value="<?php echo $this->packagedetail[0]; ?>" />
			<input type="hidden" name="paymenthistoryid" value="<?php echo $this->packagedetail[1]; ?>" />
			<input type="hidden" name="enforcestoppublishjob" value="<?php echo $this->packagedetail[2]; ?>" />
			<input type="hidden" name="enforcestoppublishjobvalue" value="<?php echo $this->packagedetail[3]; ?>" />
			<input type="hidden" name="enforcestoppublishjobtype" value="<?php echo $this->packagedetail[4]; ?>" />
			
		  	<input type="hidden" name="Itemid" id="Itemid" value="<?php echo $this->Itemid; ?>" />
		  	<input type="hidden" name="id" value="<?php if(isset($this->job)) echo $this->job->id; ?>" />
	</form>
</div>
</div>
<?php 
/*} else{ // can not add new job
	echo "<strong><font color='red'>".JText::_('JS_JOB_LIMIT_EXCEED')." <a href='index.php?option=com_wrecruit&view=employer&layout=packages&Itemid=$this->Itemid'>".JText::_('JS_EMPLOYER_PACKAGES')."</a></font></strong>";
}*/
} else{ // not allowed job posting
	//Update by Vireak on 28/06/2012
	//Add frame to this warning and some styling
	//---------------------
	echo '<div class="box-list"><div class="head-title"><h2>Oop!</h2></div>';
	echo '<span class="wr_info"><p>'.JText::_('JS_YOU_ARE_NOT_ALLOWED_TO_VIEW').'</p>';
	echo '<p>This page is reserved for the authorized employers or recruiters only. </p></span>';
	echo '</div>';
	//---------------------
}
}//ol
?>

	 <!--popup content-->
        <div id="popupContainer" class="hidden" style="text-align:left;">
            ddfffsfs
        </div>
        <div id="overlayEffect">
        </div>
       <!--end popup content--> 

<!--  <script src="chosen/jquery-1.7.2.min.js" type="text/javascript"></script>-->
<script src="components/com_wrecruit/js/chosen/chosen.jquery.js" type="text/javascript"></script>
  <script type="text/javascript"> 
	  jQuery(".chzn-select").chosen(); 
	  jQuery(".chzn-select-deselect").chosen({allow_single_deselect:true}); 
</script>